<template>
  <div>
    <div class="navMarginTop allBackground" :style="{ height: screenHeightBg }">
      <div class="DistrCotBox">
        <!-- <div class="DistrCot">
          <div class="h6">分销规则</div>
          <div class="bg-gradient">
            <div class="title">一级分销</div>
            <div class="cont">成为分销商，下级消费您获得{{ gradientObj.oneLevel }}%奖励</div>
            <div class="rounded-bl">分佣{{ gradientObj.oneLevel }}%</div>
          </div>
          <div class="bg-gradient two">
            <div class="title">二级分销</div>
            <div class="cont">成为分销商，下2级消费您获得{{ gradientObj.twoLevel }}%奖励</div>
            <div class="rounded-bl">分佣{{ gradientObj.twoLevel }}%</div>
          </div>
        </div> -->
        <div class="DistrCot">
          <div class="h6">我的收益 <span @click="handRecords">提现记录</span></div>
          <div class="incomeCot">
            <div class="incomeCotList">
              <div class="title">可提现余额（元）</div>
              <div class="money blue">{{ myIncomeObj.balance }}</div>
              <a-button type="primary" @click="goToWithDrawal">提现</a-button>
            
            </div>
            <div class="incomeCotList">
              <div class="title">今日收益（元）</div>
              <div class="money">+{{ myIncomeObj.todayIncome }}</div>
            </div>
            <div class="incomeCotList">
              <div class="title">已提现（元）</div>
              <div class="money">{{ myIncomeObj.withdrawn }}</div>
            </div>
            <div class="incomeCotList">
              <div class="title">累计收益（元）</div>
              <div class="money">{{ myIncomeObj.accumulateIncome }}</div>
            </div>
            <div class="RevenueDetails" @click="handleAdd">收益明细</div>
          </div>
        </div>
        <div class="DistrCot">
          <div class="h6">推广链接</div>
          <div class="promotion">
            <span>推广链接：</span>
            <a href="#">{{ distributionAddress }}</a>
            <a-button @click="copyText(distributionAddress)">复制</a-button>
          </div>
        </div>
        <div class="DistrCot">
          <div class="h6">邀请列表</div>
          <div class="invite">
            <a-tabs defaultActiveKey="1" @change="callbackTab">
              <a-tab-pane :tab="'全部' + '（' + ipagination.total + '）'" key="1"> </a-tab-pane>
              <a-tab-pane :tab="'直接用户'" key="2" forceRender> </a-tab-pane>
              <a-tab-pane :tab="'间接用户'" key="3" forceRender> </a-tab-pane>
            </a-tabs>
            <!-- table区域-begin -->
            <div>
              <a-table
                ref="table"
                size="middle"
                :scroll="{ x: true }"
                bordered
                rowKey="id"
                :columns="columns"
                :dataSource="dataSource"
                :pagination="ipagination"
                :loading="loading"
                class="j-table-force-nowrap"
                @change="handleTableChange"
              >
                <span slot="action" slot-scope="text, record">
                  <a @click="handleEdit(record)">编辑</a>

                  <a-divider type="vertical" />
                  <a-dropdown>
                    <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                    <a-menu slot="overlay">
                      <a-menu-item>
                        <a @click="handleDetail(record)">详情</a>
                      </a-menu-item>
                      <a-menu-item>
                        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                          <a>删除</a>
                        </a-popconfirm>
                      </a-menu-item>
                    </a-menu>
                  </a-dropdown>
                </span>
              </a-table>
            </div>
          </div>
        </div>
      </div>
    </div>
    <global-footer />
    <income-cot-modal ref="modalForm" :posterObj="posterObj"></income-cot-modal>
    <withdrawal-modal ref="modalForm1" :posterObj="posterObj"></withdrawal-modal>
  </div>
</template>

<script>
import Vue from 'vue'
import { getAction } from '@/api/manage'
import GlobalFooter from '@/components/page/GlobalFooter'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import WithdrawalModal from './component/WithdrawalModal'
import IncomeCotModal from './component/IncomeCotModal'
import { ACCESS_CODE } from '@/store/mutation-types'

import { referralCode } from '@/utils/util'
export default {
  name: 'DistriBution',
  mixins: [JeecgListMixin],
  components: {
    GlobalFooter,
    WithdrawalModal,
    IncomeCotModal
  },
  props: {},
  data() {
    return {
      gradientObj: {},
      myIncomeObj: {},
      screenWidth: '',
      screenHeight: '',
      screenHeightBg: '',
      // 表头
      columns: [
        {
          title: '用户昵称',
          align: 'center',
          dataIndex: 'realname',
        },
        {
          title: '订单量',
          align: 'center',
          dataIndex: 'orderNumber',
        },
        // {
        //   title: '状态',
        //   align: 'center',
        //   dataIndex: 'status_dictText',
        // },
        {
          title: '累积消费',
          align: 'center',
          dataIndex: 'accumulateConsumption',
        },
        {
          title: '邀请人数',
          align: 'center',
          dataIndex: 'inviteNumber',
        },
        {
          title: '注册时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align: 'center',
        //   fixed: 'right',
        //   width: 147,
        //   scopedSlots: { customRender: 'action' },
        // },
      ],
      url: {
        list: '/sys/user/getMyUser',
        delete: '/sys/tenant/delete',
        deleteBatch: '/sys/tenant/deleteBatch',
      },
      distributionAddress: '',
      posterObj:{},
    }
  },
  created() {
    this.queryParam.type = '0'
  },
  computed: {},

  mounted() {
    this.$nextTick(function () {
      this.screenWidth = window.innerWidth
      this.screenHeight = window.innerHeight
      this.screenHeightBg = this.screenHeight - 120 + 'px'

      this.distributionAddress = referralCode()
      console.log('this.distributionAddress', this.distributionAddress)
    })
    // this.funthree()
    this.getDistributionSet()
    this.getMyIncome()
  },
  methods: {
    handRecords(){
      this.$refs.modalForm1.add()
      this.$refs.modalForm1.title = '提现记录'
      this.$refs.modalForm1.disableSubmit = false
    },
    handleAdd(index) {
      // this.posterObj = this.imageData[index]
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '收益明细'
      this.$refs.modalForm.disableSubmit = false
    },
    // funone() {
    //   setTimeout(function(){
    //     that.callbackTab('1')
    //   },1000)
    // },
    // funtwo() {
    //   let that = this
    //   setTimeout(function(){
    //     that.callbackTab('2')
    //   },3000)

    // },
    // funthree() {
    //      this.funone()
    //      this.funtwo()
    // },
     //提现记录
     getWithdrawal() {
      this.tableLoading = true
      getAction('/withdrawal/api/list?userId='+ this.userInfo().id)
        .then((res) => {
          console.log('res', res)
        })
        .finally(() => {
          this.tableLoading = false
        })
    },
    
    //分销规则
    getDistributionSet() {
      getAction('/distributionset/api/getDistributionSet')
        .then((res) => {
          console.log('res', res)
          this.gradientObj = res.result
        })
        .finally(() => {
          this.tableLoading = false
        })
    },
    //我的收益
    getMyIncome() {
      getAction('/myincome/MyIncome/getMyIncome')
        .then((res) => {
          console.log('res', res)
          this.myIncomeObj = res.result
        })
        .finally(() => {
          this.tableLoading = false
        })
    },
    //复制
    copyText(data) {
      const text = data // 要复制的文本内容
      const el = document.createElement('textarea')
      el.value = text
      document.body.appendChild(el)
      el.select()
      document.execCommand('copy')
      document.body.removeChild(el)
      this.$message.success('复制地址成功')
    },
    goToWithDrawal() {
      if(this.myIncomeObj.balance <=99 ){
        this.$message.info('提现金额不少于100')
      }else{
        this.$router.push({ path: '/chatgpt/WithDrawal' })
      }

    },
    handleAdd: function () {
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '收益明细'
      this.$refs.modalForm.disableSubmit = false
    },
    callbackTab(key) {
      console.log('key', key)
      if (key === '1') {
        console.log('11111111111111111111')
        this.queryParam.type = '0'
        this.loadData()
      } else if (key === '2') {
        console.log('22222222222222222222')
        this.queryParam.type = '1'
        this.loadData()
      } else if (key === '3') {
        console.log('3333333333333333')
        this.queryParam.type = '2'
        this.loadData()
      }
    },
    apiPackageRechargeL() {
      getAction('/packagerecharge/packageRecharge/list')
        .then((res) => {
          console.log('res', res)
          this.redisInfo = res.result.records
        })
        .finally(() => {
          this.tableLoading = false
        })
    },
  },
}
</script>

<style lang="less" scoped>
.DistrCotBox {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden auto;
  .DistrCot {
    margin-bottom: 30px;
    float: left;
    width: 100%;
    .h6 {
      font-size: 18px;
      font-weight: 500;
      margin-bottom: 25px;
      color: black;
      display: flex;
      justify-content: space-between;
      span{
        color: #999;
        cursor: pointer;
        font-size: 14px;
      }
    }
    .bg-gradient {
      padding-bottom: 15px;
      padding-top: 15px;
      padding-left: 20px;
      padding-right: 20px;
      background: linear-gradient(90deg, #e1ab7a, white);
      width: 300px;
      box-shadow: 1px 1px 10px 3px #e8e8e8;
      position: relative;
      float: left;
      margin-right: 30px;
      border-radius: 5px;
      .title {
        font-size: 18px;
        color: #6a3d15;
      }
      .cont {
        margin-top: 12px;
        color: #6a3d15;
        font-size: 14px;
      }
      .rounded-bl {
        padding-bottom: 6px;
        padding-top: 6px;
        padding-left: 15px;
        padding-right: 15px;
        background-color: #d3af8d;
        position: absolute;
        right: 0;
        top: 0;
        border-bottom-left-radius: 5px;
        font-size: 13px;
      }
      &.two {
        background: linear-gradient(90deg, #b36ffc, white);
        .title,
        .cont,
        .rounded-bl {
          color: #3e2077;
        }
        .rounded-bl {
          background-color: #ae80f1;
        }
      }
    }
    .incomeCot {
      padding: 20px;
      background-color: #f8f8f8;
      display: flex;
      justify-content: space-around;
      position: relative;
      padding-right: 15%;
      .incomeCotList {
        button {
          margin-top: 12px;
        }
        .title {
          font-size: 13px;
          color: #101010;
        }
        .money {
          font-size: 32px;
          margin-top: 12px;
          color: black;
          &.blue {
            color: #00abff;
          }
        }
      }
      .RevenueDetails {
        position: absolute;
        right: 20px;
        top: 20px;
        color: #b36ffc;
        cursor: pointer;
      }
    }
    .promotion {
      button {
        margin-left: 10px;
      }
    }
  }
}

@media screen and (max-width: 767px) {
  .DistrCotBox {
    .DistrCot {
      display: flex;
    flex-direction: column;
    justify-content: center;
      .bg-gradient {
        width: 94%;
        margin: 0 auto 10px;
      }
      .incomeCot{
        padding-right: 0;
        .RevenueDetails{
          bottom: 20px;
          top: unset;
        }
        .incomeCotList{
          .money{
            font-size: 20px;
          }
        }
      }
      .promotion{
        display: flex;
        a{
          flex: 1;
        }
      }
    }
  }
}
</style>